package com.carrental.integration.controller;

import com.carrental.common.result.Result;
import com.carrental.integration.service.SmsComponent;
import com.carrental.integration.service.SmsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 短信服务控制器
 * 提供短信相关的API接口
 */
@Tag(name = "短信服务接口", description = "提供短信相关的API接口")
@RestController
@RequestMapping("/sms")
public class SmsController {

    @Resource
    private SmsService smsService;

    @Resource
    private SmsComponent smsComponent;

    /**
     * 发送验证码短信
     *
     * @param phoneNumber 手机号码
     * @param code 验证码
     * @return 发送结果
     */
    @Operation(summary = "发送验证码短信", description = "向指定手机号发送验证码短信")
    @GetMapping("/verification-code")
    public Result<Boolean> sendVerificationCode(
            @Parameter(description = "手机号码", required = true) @RequestParam String phoneNumber,
            @Parameter(description = "验证码", required = true) @RequestParam String code) {
        boolean result = smsComponent.sendCode(phoneNumber, code);
        return result ? Result.success(true) : Result.failed("发送验证码短信失败");
    }

    /**
     * 发送通知短信
     *
     * @param phoneNumber 手机号码
     * @param templateParams 模板参数
     * @return 发送结果
     */
    @Operation(summary = "发送通知短信", description = "向指定手机号发送通知短信")
    @GetMapping("/notification")
    public Result<Boolean> sendNotification(
            @Parameter(description = "手机号码", required = true) @RequestParam String phoneNumber,
            @Parameter(description = "模板参数", required = true) @RequestBody Map<String, String> templateParams) {
        boolean result = smsService.sendNotification(phoneNumber, templateParams);
        return result ? Result.success(true) : Result.failed("发送通知短信失败");
    }

    /**
     * 发送营销短信
     *
     * @param phoneNumber 手机号码
     * @param templateParams 模板参数
     * @return 发送结果
     */
    @Operation(summary = "发送营销短信", description = "向指定手机号发送营销短信")
    @GetMapping("/marketing")
    public Result<Boolean> sendMarketing(
            @Parameter(description = "手机号码", required = true) @RequestParam String phoneNumber,
            @Parameter(description = "模板参数", required = true) @RequestBody Map<String, String> templateParams) {
        boolean result = smsService.sendMarketing(phoneNumber, templateParams);
        return result ? Result.success(true) : Result.failed("发送营销短信失败");
    }
} 